package ve.ucv.patologiaocular.dao;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import java.util.Map;

import ve.ucv.patologiaocular.domain.Usuario;

public class InterAutenticacion implements Interceptor {

  /**
	 * 
	 */
	private static final long serialVersionUID = -4252327333464258252L;
	
	public void destroy() { }
	public void init() { }
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		Map<String, Object> session = actionInvocation.getInvocationContext().getSession();
		Usuario usuario = (Usuario) session.get("User");
		if (usuario == null) {
			return Action.LOGIN;
		} 
		else {
			Action action = (Action) actionInvocation.getAction();
			if (action instanceof UsuarioHabilitado) {
				((UsuarioHabilitado) action).setUsuario(usuario);
			}
			return actionInvocation.invoke();
		}
	}
}
